﻿using System;
using System.Drawing;
using System.Text;

namespace VitCode.Castle.Helper
{
    /// <summary>
    /// 转换的扩展类，增加了更多Convert没有提供的转换方法
    /// </summary>
    public sealed class ConvertExtent
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string[] ToArrayString(int[] input)
        {
            string[] result = new string[input.Length];
            for (int i = 0; i < input.Length; i++)
            {
                result[i] = Convert.ToString(input[i]);
            }

            return result;
        }

        /// <summary>
        /// 把input数组转换成为一个以split分割的字符串
        /// </summary>
        /// <param name="input">输入的Int型</param>
        /// <param name="split">分割符号</param>
        /// <returns></returns>
        public static string ToString(string[] input, string split)
        {
            StringBuilder result = new StringBuilder();
            int size=input.Length;
            int last=size-1;
            for (int i = 0; i < size; i++)
            {
                if(input[i]!=null)
                {
                    result.Append(input[i].Trim());
                    if(i!=last)
                        result.Append(split);
                }
            }

            return result.ToString();
        }

        /// <summary>
        /// 把input数组转换成为一个以split分割的字符串
        /// </summary>
        /// <param name="input">输入的Int型</param>
        /// <param name="split">分割符号</param>
        /// <returns></returns>
        public static string ToString(int[] input, string split)
        {
            StringBuilder result = new StringBuilder();
            for (int i = 0; i < input.Length; i++)
            {
                result.Append(input[i]);
                result.Append(split);
            }

            return result.ToString();
        }

        /// <summary>
        /// 把htmlColor转换为Color对象
        /// </summary>
        /// <param name="htmlColor"></param>
        /// <returns></returns>
        /// <remarks>
        /// 直接使用<see cref="ColorTranslator"/>对象进行转换
        /// </remarks>
        public static Color ToColor(string htmlColor)
        {
            return ColorTranslator.FromHtml(htmlColor);
        }

        /// <summary>
        /// 把color转换为Html字符串格式
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public static string ToHtmlColor(Color color)
        {
            return ColorTranslator.ToHtml(color);
        }
    }
}
